from django.db import models
from django.contrib.auth.models import User
from grades.models import Grade 


# Create your models here.
GENDER_CHOICES=[
    ('男', '男'),
    ('女', '女'),
]

class Student(models.Model):
    student_number = models.CharField(max_length=20, unique=True,verbose_name="学籍号")
    student_name = models.CharField(max_length=30,unique=True,verbose_name="姓名")
    gender = models.CharField(max_length=1,verbose_name="性别",choices=GENDER_CHOICES)
    birthday = models.DateField(verbose_name="出生日期",help_text="格式例如；2022-05-03")
    contact = models.CharField(max_length=20,verbose_name="联系方式",help_text="格式例如；13812345678")
    address = models.TextField(max_length=100,verbose_name="地址",help_text="格式例如；北京市海淀区XXX")

    # 设置一对一关系，关联到User模型
    user = models.OneToOneField(User,on_delete=models.CASCADE) #设置外键

    # 设置外键，关联到Grade模型 班级表一对多
    grade = models.ForeignKey(Grade, on_delete=models.CASCADE, verbose_name="年级")

    def __str__(self):
        return self.user.username
    
    class Meta:
        db_table = 'student'  # 设置数据库表名
        verbose_name = "学生信息"  # 设置模型的中文名称
        verbose_name_plural = "学生信息"
        ordering = ['student_number']  # 设置默认排序方式